package com.mine.photohandler.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.ToggleButton;

import com.bumptech.glide.Glide;
import com.mine.photohandler.R;
import com.mine.photohandler.base.AbsBaseAdapter;
import com.mine.photohandler.util.Bimp;
import com.mine.photohandler.util.ImageItem;

/**
 * 手机相册适配器
 */

public class AlbumAdapter extends AbsBaseAdapter<ImageItem> {
    private OnItemCancledListener listener;

    public AlbumAdapter(Context context, boolean isNeedToRemember, int resid) {
        super(context, isNeedToRemember, resid);
    }

    @Override
    public void bindDatas(final int position, View convertView, ViewHolder viewHolder, ImageItem data) {
        Glide.with(context)
                .load(data.imagePath)
                .into((ImageView) viewHolder.getView(R.id.image_view));
        ToggleButton toggleButton = viewHolder.getView(R.id.toggle_button);

        if (map_isSelected.get(position).isSelected() || Bimp.tempSelectBitmap.contains(data)){
            viewHolder.getView(R.id.toggle).setVisibility(View.VISIBLE);
            toggleButton.setChecked(true);
        }else {
            viewHolder.getView(R.id.toggle).setVisibility(View.GONE);
            toggleButton.setChecked(false);
        }

        toggleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null){
                    listener.onItemCancled(position);
                }
            }
        });

    }

    public interface OnItemCancledListener{
        void onItemCancled(int position);
    }

    public void setOnItemCancledListener(OnItemCancledListener listener){
        this.listener = listener;
    }
}
